package cn.itcast.demo.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
@EnableConfigurationProperties(JdbcProperties.class) //注册使用属性类2.2以后
public class JdbcConfig {

    @Autowired
    private JdbcProperties props;

    @Bean
    public DataSource getDataSource(){
        DruidDataSource dataSource = new DruidDataSource();

        dataSource.setDriverClassName(props.getDriverClassName());

        dataSource.setUsername(props.getUsername());


        return dataSource;
    }
}
